﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Net;
using System.Web;
using System.Web.Mvc;
using TS2015.Models;
using Kendo.Mvc.Extensions;
 
using System.IO;
using Kendo.Mvc.UI;

namespace TS2015.Areas.Admin.Controllers
{
    public class TbLogServicesController : Controller
    {
        private TS2015Context db = new TS2015Context();

        // GET: Admin/TbLogServices
        public async Task<ActionResult> Index()
        {
            if (!CheckRole.IsRole("log_sv_index", Session["Function"] as string[]))
                return Redirect("~/accessdenied.html");

            if (!Request.IsAjaxRequest())
                return View(await db.TbLogServices.OrderByDescending(e=>e.LogID).ToListAsync());

            return PartialView(await db.TbLogServices.OrderByDescending(e => e.LogID).ToListAsync());       
        }
        public ActionResult Editing_DestroyLogServices([DataSourceRequest] DataSourceRequest request, TbLogService data)
        {
            if (!CheckRole.IsRole("log_sv_delete", Session["Function"] as string[]))
                return Redirect("~/accessdenied.html");

            if (data != null)
            {
                TbLogService itemdata = db.TbLogServices.First(item => item.LogID == data.LogID);
                db.TbLogServices.Remove(itemdata);
                db.SaveChanges();
            }
            return Json("Ok");
        }
        public ActionResult Editing_ReadLogServices([DataSourceRequest] DataSourceRequest request)
        {
            if (!CheckRole.IsRole("log_sv_index", Session["Function"] as string[]))
                return Redirect("~/accessdenied.html");

            var data = db.TbLogServices;

            return Json(data.ToDataSourceResult(request));
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
